@echo off
Set IC_TESTS_SOURCE_FOLDER=%~dp0test
Set IC_TESTS_OUTPUT_FOLDER=%~dp0TestsResults
Set IC_RUN_STRING=java IC.Compiler

cd /D %~dp0

Echo **** %TIME% Compiling, Please wait..
cmd /c ant clean 1> nul
cmd /c ant build 1> nul
cmd /c ant scanner 1> nul
cmd /c ant parser 1> nul
cmd /c ant libparser 1> nul

mkdir %IC_TESTS_OUTPUT_FOLDER%

cd /D %~dp0classes

Echo **** %TIME% Starting test session for files in %IC_TESTS_SOURCE_FOLDER%
for /f "delims=|" %%f in ('dir /b %~dp0test\*.ic') do (
	Echo.
	Echo --Running test for "%IC_TESTS_SOURCE_FOLDER%\%%f"..
	%IC_RUN_STRING% "%IC_TESTS_SOURCE_FOLDER%\%%f" -L"%~dp0test\libic.sig" -print-ast > "%IC_TESTS_OUTPUT_FOLDER%\%%f.output.txt"
	if %errorlevel% equ 0 (findstr "error" "%IC_TESTS_OUTPUT_FOLDER%\%%f.output.txt" 
		Echo Done. ) else (Echo ----ERROR: Test finished with error %errorlevel%)
)
Echo.
Echo Opening results folder..
start %IC_TESTS_OUTPUT_FOLDER%
timeout 15